﻿using MDIApplication.Classes;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MDIApplication
{
    public partial class SearchDisplayForStaff : Form
    {
        public SearchDisplayForStaff(string firstName, string lastName)
        {
            InitializeComponent();
            lblfirstName.Text = firstName;
            lbllastName.Text = lastName;
        }

        

        private void SearchDisplayForStaff_Load(object sender, EventArgs e)
        {
            HousekeepingStaffManagementDBManager db = new HousekeepingStaffManagementDBManager();
            Staff s = db.getStaffByStaffName(lblfirstName.Text, lbllastName.Text);
            lblaccountID.Text = s.staffId;
            lblcontactNumber.Text = s.contactNo.ToString();
            lbldob.Text = s.dob.ToLongDateString();
            lblgender.Text = s.gender;
            lbladdress.Text = s.address;
            lblstaffPosition.Text = s.staffPosition;
            lblbankAcctType.Text = s.acctType;
            lblbankAcctNum.Text = s.acctNo;
            
            
         
        }

        UpdateStaffDetail updateStaffDetailChild;
        private void updateinfobtn_Click(object sender, EventArgs e)
        {
            HousekeepingStaffManagementDBManager db = new HousekeepingStaffManagementDBManager();
            Staff s = db.getStaffByStaffName(lblfirstName.Text, lbllastName.Text);

            //transfer 
            CloseAllForms();
            if (updateStaffDetailChild == null)
            {
                updateStaffDetailChild = new UpdateStaffDetail(lblfirstName.Text, lbllastName.Text);
                updateStaffDetailChild.MdiParent = this.MdiParent;
                updateStaffDetailChild.Location = new Point(0, 0);
                // Display the form.
                updateStaffDetailChild.Show();
                updateStaffDetailChild.Activate();
            }
        }

        #region toolStrip
        UpdateRoomInfo updateRoomInfoChild;
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            CloseAllForms();
            if (updateRoomInfoChild == null)
            {
                updateRoomInfoChild = new UpdateRoomInfo();
                updateRoomInfoChild.MdiParent = this.MdiParent;
                updateRoomInfoChild.Location = new Point(0, 0);
                // Display the form.
                updateRoomInfoChild.Show();
                updateRoomInfoChild.Activate();
            }

        }

        SearchForStaffHousekeepDuty dutyAllocationChild;
        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            CloseAllForms();
            if (dutyAllocationChild == null)
            {
                dutyAllocationChild = new SearchForStaffHousekeepDuty();
                dutyAllocationChild.MdiParent = this.MdiParent;
                dutyAllocationChild.Location = new Point(0, 0);
                // Display the form.
                dutyAllocationChild.Show();
                dutyAllocationChild.Activate();
            }
        }

        SearchForStaff updateStaffChild;
        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            CloseAllForms();
            if (updateStaffChild == null)
            {
                updateStaffChild = new SearchForStaff();
                updateStaffChild.MdiParent = this.MdiParent;
                updateStaffChild.Location = new Point(0, 0);
                // Display the form.
                updateStaffChild.Show();
                updateStaffChild.Activate();
            }
        }
        #endregion toolStrip

        #region CloseAllForms
        private void CloseAllForms()
        {
            Form[] formToClose = null;
            int i = 1;
            foreach (Form form in Application.OpenForms)
            {
                if (form != this && form.IsMdiChild) //this is form1
                {
                    Array.Resize(ref formToClose, i);
                    formToClose[i - 1] = form;
                    i++;
                }
            }
            if (formToClose != null)
            {
                for (int j = 0; j < formToClose.Length; j++)
                {
                    formToClose[j].Close();
                }
                updateRoomInfoChild = null;
                dutyAllocationChild = null;
                updateStaffChild = null;
                updateStaffDetailChild = null;
            }
        }
        #endregion CloseAllForms


        }
        

        
    }

